<template>
  <div>
    <div
      style="font-size: 16px;font-weight: 500;color: #1D2129;margin-bottom: 16px;"
    >
      校外体育中心人员分布情况
    </div>
    <div
      id="Chart1"
      style="width:100%;height:300px;margin-top:-20px;margin-left:-15px"
    ></div>
  </div>
</template>

<script>
import * as echarts from "echarts";
import { get_sheet6_num_data } from "@/api/statistics";

export default {
  name: "SchoolType",
  data() {
    return {
      chartInstance: null,
      establishment: [],
      noestablishment: []
    };
  },
  mounted() {
    this.datalist();
  },

  methods: {
    async datalist() {
      await get_sheet6_num_data().then(res => {
        this.establishment = res.data.onList;
        this.noestablishment = res.data.outList;
      });
      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(document.getElementById("Chart1"));
      // 指定图表的配置项和数据
      var option;
      option = {
        tooltip: {
          trigger: "axis"
        },
        legend: {
          data: ["在编", "聘用"]
        },

        calculable: true,
        xAxis: [
          {
            type: "category",
            // prettier-ignore
            data: ['管理人员', '指导教师', '教练员']
          }
        ],
        yAxis: [
          {
            type: "value"
          }
        ],
        series: [
          {
            name: "在编",
            type: "bar",
            data: this.establishment
          },
          {
            name: "聘用",
            type: "bar",
            data: this.noestablishment
          }
        ]
      };
      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);
      // 监听父元素大小变化 刷新图表
      var ro = new ResizeObserver(entries => {
        for (let entry of entries) {
          const cr = entry.contentRect;
          myChart.resize();
        }
      });
      ro.observe(Chart1);
    }
  }
};
</script>

<style scoped>
.dianidan {
  width: 7px;
  height: 7px;
  margin-right: 5px;
  margin-top: 3px;
}
</style>
